﻿using System;
using System.Windows;

namespace DotNetUI.Controls.Shapes
{
    /// <summary>
    /// 算法扩展
    /// </summary>
    public static class MathExtension
    {
        /// <summary>
        /// 获取坐标点
        /// </summary>
        /// <param name="angle"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static Point GetPoint(this double angle,double r)
        {
            return angle.GetPoint(r,r);
        }
        /// <summary>
        /// 根据角度获取坐标点
        /// </summary>
        /// <param name="angle"></param>
        /// <param name="rx">半径X</param>
        /// <param name="ry">半径Y</param>
        /// <returns></returns>
        public static Point GetPoint(this double angle, double rx, double ry)
        {
            var rad = angle.ToRadian();
            Point startPoint = new Point();
            startPoint.X = rx * ry / Math.Sqrt(Math.Pow(ry, 2) + Math.Pow(rx * Math.Tan(rad), 2));
            startPoint.X *= Math.Cos(rad) > 0 ? 1 : -1;
            startPoint.Y = startPoint.X * Math.Tan(rad);
            return startPoint;
        }
        /// <summary>
        /// 给出点位请
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public static double GetR(this Point point)
        {
            return  Math.Sqrt(Math.Pow(point.X,2)+Math.Pow(point.Y,2));
        }

        /// <summary>
        /// 角度转弧度
        /// </summary>
        /// <param name="angle"></param>
        /// <returns></returns>
        public  static double ToRadian(this double angle)
        {
            return angle / 180.0 * Math.PI;
        }
    }
}
